package json;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.List;

/**
 * @Author: ycy
 * @CreateDate: 2018/9/28 11:11
 */
public class JsonDemo {

  public static void main(String[] args) {

    List<String> list = Lists.newLinkedList();
//    list.add("房东广森\"撒旦法东,撒扥功夫贷\"");
    list.add("世上最强“海贼2“");
    String str = JSONObject.toJSONString(list);
    System.out.println(str);
    //把json字符转化成object
    List<String> jsonObject = (List<String>) JSONObject.parse(str);
    System.out.println(jsonObject);
    String str2 = JSONObject.toJSONString(jsonObject);
    System.out.println(str2);
//    while(true){
//      try {
//        Thread.sleep(1000);
//      } catch (InterruptedException e) {
//        e.printStackTrace();
//      }
//    }


    Gson gson = new GsonBuilder().create();
    String li = null;
    PackageMaterial packageMaterial = gson.fromJson(li, PackageMaterial.class);
    System.out.println(packageMaterial);

  }

  private class PackageMaterial {

    private String name;
    private String itag;
    private String cover_square;
    private String cover_horizon;
    private String cover_vertical;

    public String getName() {
      return name;
    }

    public void setName(String name) {
      this.name = name;
    }

    public String getItag() {
      return itag;
    }

    public void setItag(String itag) {
      this.itag = itag;
    }

    public String getCover_square() {
      return cover_square;
    }

    public void setCover_square(String cover_square) {
      this.cover_square = cover_square;
    }

    public String getCover_horizon() {
      return cover_horizon;
    }

    public void setCover_horizon(String cover_horizon) {
      this.cover_horizon = cover_horizon;
    }

    public String getCover_vertical() {
      return cover_vertical;
    }

    public void setCover_vertical(String cover_vertical) {
      this.cover_vertical = cover_vertical;
    }
  }


}
